package cn.dglydrpy.fundmanagement.controller;

import cn.dglydrpy.fundmanagement.service.IInvestmentDiaryService;
import cn.dglydrpy.fundmanagement.service.dto.InvestmentDiaryDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/investmentDiarys")
public class InvestmentDiaryController {

    @Autowired
    private IInvestmentDiaryService investmentDiaryService;

    @PostMapping("/addInvestmentDiary")
    public void addInvestmentDiary(@RequestBody InvestmentDiaryDto investmentDiaryDto) {
        investmentDiaryService.saveInvestmentDiary(investmentDiaryDto);
    }

    @PostMapping("/updateInvestmentDiary")
    public void updateInvestmentDiary(@RequestBody InvestmentDiaryDto investmentDiaryDto) {
        investmentDiaryService.updateInvestmentDiary(investmentDiaryDto);
    }

    @PostMapping("/deleteInvestmentDiary/{id}")
    public void deleteInvestmentDiary(@PathVariable Long id) {
        investmentDiaryService.deleteInvestmentDiary(id);
    }

    @GetMapping("/{id}")
    public InvestmentDiaryDto getInvestmentDiaryById(@PathVariable Long id) {
        return investmentDiaryService.getInvestmentDiaryById(id);
    }

    @GetMapping("/getInvestmentDiarysByConditions")
    public Page<InvestmentDiaryDto> getInvestmentDiarysByConditions(
            @RequestParam String fundCode,
            @RequestParam String portfolioId,
            @RequestParam String category,
            @RequestParam int pageNo,
            @RequestParam int pageSize) {
        return investmentDiaryService.getInvestmentDiarysByConditions(fundCode, portfolioId, category, pageNo, pageSize);
    }

    @GetMapping("/getAllInvestmentDiarys")
    public List<InvestmentDiaryDto> getAllInvestmentDiarys() {
        return investmentDiaryService.getAllInvestmentDiarys();
    }
}